<template>
  <div class="shimintousu">
    <ModalTitle title="事案件高发类型预警">
      <TimeTab @timeReturnFn="timeReturnFn" />
    </ModalTitle>
    <div class="table">
      <div class="table-th">
        <div class="name">同类事件</div>
        <div class="phone">案件数量</div>
      </div>
      <div class="table-tb">
        <div class="item" v-for="(item, index) in list" :key="index">
          <div class="name">{{ item.eventTitle }}</div>
          <div class="phone">{{ item.eventNum }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import TimeTab from "@/components/TimeTab/Index.vue";
import ModalTitle from "@components/ModalTitle/Index.vue";
import { FengXianJianKong } from "@/api/zhangzi/index";
export default {
  components: { ModalTitle, TimeTab },
  data() {
    return {
      beginTime: moment().format("YYYY-MM-DD") + " 00:00:00",
      endTime: moment().format("YYYY-MM-DD") + " 23:59:59",
      list: [],
      moment,
    };
  },
  mounted() {
    this.getCaseType();
  },
  methods: {
    timeReturnFn(point) {
      switch (point.value) {
        case 0:
          this.beginTime = moment().format("YYYY-MM-DD") + " 00:00:00";
          this.endTime = moment().format("YYYY-MM-DD") + " 23:59:59";
          this.getCaseType()
          break;
        case 1:
          this.beginTime = moment().week(moment().week()).startOf('week').format('YYYY-MM-DD') + ' 00:00:00';
          this.endTime = moment().format("YYYY-MM-DD") + " 23:59:59";
          this.getCaseType()
          break;
        case 2:
          this.beginTime = moment().startOf('month').format('YYYY-MM-DD') + ' 00:00:00';
          this.endTime = moment().format("YYYY-MM-DD") + " 23:59:59";
          this.getCaseType()
          break;
        case 3:
          this.beginTime = moment().year() + '-01-01 00:00:00'
          this.endTime = moment().format('YYYY-MM-DD') + ' 23:59:59'
          this.getCaseType()
          break;
        default:
          break;
      }
    },
    async getCaseType() {
      const { success, data, message } = await FengXianJianKong.getCaseTypeAPI({
        beginTime: this.beginTime,
        endTime: this.endTime,
      });
      if (success) {
        this.list = data;
      } else {
        this.$message.error(message);
      }
    },
  },
};
</script>

<style lang="less" scoped>
.shimintousu {
  width: 100%;
  height: 100%;
  .table {
    width: 100%;
    height: calc(100% - 3.8rem - 1rem);
    margin-top: 1rem;
    .table-th,
    .table-tb {
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 3rem;
      padding: 0 1rem;
      .name {
        flex: 1;
        height: 100%;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        font-size: 1.4rem;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        color: #fff;
        line-height: 3rem;
        white-space: nowrap;
      }
      .phone {
        width:  10rem;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 1.4rem;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        color: #fff;
        line-height: 3rem;
        white-space: nowrap;
      }
    }
    .table-tb {
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      align-items: center;
      width: 100%;
      height: calc(100% - 3rem - 0.5rem);
      margin-top: 0.5rem;
      overflow-y: auto;
      .item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        height: 3rem;
        margin-bottom: 1rem;
      }
    }
  }
}
</style>